<template>
<h2>修改会员等级</h2>

<table>

    <tr>
        <th>
            会员级别名称
        </th>
        <th>
            <input type="text" v-model="bb.dname">
        </th>
    </tr>

    <tr>
        <th>
            累计最低消费额(元)
        </th>
        <th>
            <input type="text"  v-model="bb.xiaoFeie">
        </th>
    </tr>

    <tr>
        <th>
        
        </th>
        <th>
           <button @click="Xg">修改</button>
        </th>
    </tr>

</table>




</template>

<script setup lang="ts">

 import { useRouter,useRoute,createRouter}from 'vue-router'
import{onMounted, ref} from'vue'
import axios from 'axios';

    const route =useRoute();
    const router =useRouter();
    const aa = route.params.Did;
 
    const bb =ref({
        did: aa,
  dname: "",
  xiaoFeie: 0


    })


    const Xg =()=>{

            if(bb.value.dname=="")
            {
                alert('会员等级名称不能为空')
                return ;
            }

            if(bb.value.xiaoFeie==0)
            {
                alert('会员消费额度不能为空')
                return ;
            }
            

            axios.put('https://localhost:7296/api/Dengji/UpdateD',bb.value).then(res=>{

                if(res.data>0)
            {
                alert('修改成功') 
                router.push({
                    name:'ShowDengji'
                })
            }
            else
            {
                alert('修改失败')
            }
            })
            .catch(error=>{
                console.log(error)
            })


    }


        onMounted(()=>{
            FanTian();
        })

        const FanTian=()=>{

            axios .get('https://localhost:7296/api/Dengji/FanTianD?id='+aa).then(res=>{

                    
                bb.value=res.data;
            })
            .catch(error=>{
                console.log(error);
            })
            


        }

</script>